#include "checkablemenuaction.h"
#include <QHBoxLayout>

CheckableMenuAction::CheckableMenuAction(const QString &text, QObject *parent)
    : QWidgetAction(parent)
{
    QWidget *container = new QWidget;
    QHBoxLayout *layout = new QHBoxLayout(container);
    layout->setContentsMargins(6, 0, 6, 0);
    layout->setSpacing(6);

    checkBox = new QCheckBox(text, container);
    layout->addWidget(checkBox);

    setDefaultWidget(container);

    connect(checkBox, &QCheckBox::toggled, this, &CheckableMenuAction::toggled);

    setupStyleSheet();
}

bool CheckableMenuAction::isChecked() const
{
    return checkBox->isChecked();
}

void CheckableMenuAction::setChecked(bool checked)
{
    checkBox->setChecked(checked);
}

void CheckableMenuAction::setupStyleSheet()
{
    checkBox->setStyleSheet(
        "QCheckBox {"
        "    spacing: 5px;"
        "}"
        "QCheckBox::indicator {"
        "    width: 13px;"
        "    height: 23px;"
        "}"
        "QCheckBox::indicator:unchecked {"
        "    image: url(:/images/C:/Users/Administrator/Downloads/check_box_nor.png);"
        "}"
        "QCheckBox::indicator:checked {"
        "    image: url(:/images/C:/Users/Administrator/Downloads/check_box_dis.png);"
        "}"
    );
}
